#pragma  once

#include <QGraphicsItem>
#include <QPainter>
#include <QGraphicsScene>

using namespace std;

class QGraphicsSceneMouseEvent;
class SceneView;
class PipeLine;
class sim;
class Title;
class PropertiesModel;
class Delegate;

static const enum NodeType_t {INLET, OUTLET, SPLITTER, BLANK};

class Node : public QObject, public QGraphicsItem
{
	Q_OBJECT

public:
	Node(SceneView *_scene, QString _name, QPointF _pos);
	Node(SceneView *_scene);
	~Node();
	Title *title;
	
	QRectF boundingRect() const;
	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
	void addInletPipe(PipeLine *pipeline);
	void addOutletPipe(PipeLine *pipeline);
	void removeInletPipe(PipeLine *pipeline);
	void removeOutletPipe(PipeLine *pipeline);
	void setAccepted(bool b){ accepted = b; }
	bool isAccepted(){return accepted;};
	PropertiesModel* getModel(){ return model; }
    NodeType_t getType();
protected:
	void mousePressEvent(QGraphicsSceneMouseEvent *event);
	void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
	void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
	QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private:
	PropertiesModel* model;
	NodeType_t type;
	QList<PipeLine*> inletList;
	QList<PipeLine*> outletList;
	SceneView *scene;
	bool accepted;
	
	//void log(const QString &text){scene->main->log(text);}
	QString getDefaultName();
	void init_model();
	QString getStringType();
	
	//QString OilModelList;
private slots:
	void getModelData(const int &parent_row, const int &row, const QVariant &value);
	void updateProperties();
	//QString OilModelListChanged(QString list = "");
signals:
	void setModelData(const int &parent_row, const int &row, const QVariant &value);

};
